import http from '../../../http/http'
import * as url from '../../../api/cfApi'
import {Message} from 'element-ui';
const state = {
  vipRegister: {
  
  },
  vipRecharge: {
  
  }
}
const mutations ={

}
const actions ={
  addVipAC({commit},obj){
    console.log('addVipAC()',obj)
    //todo: 405 错误
  return http({
    method: 'post',
    url: '/api'+url.ADDVIP,
    data: obj
    }).then(res=> {
      console.log(res)
      if (res.data.code === '200') {
        //  成功,将数据写到vuex里面,跳转成功页面
        console.log(res.data)
        // commit('writeNewVip')
      } else if (res.data.code ==='400') {
        Message.error('注册失败,请重试')
      }
    }).catch(err => {
      console.log('注册失败',err)
    })
  },// 添加vip会员
  searchVipAC({commit},obj) {
    console.log('查询vip',obj)
    return http({
      url: '/api'+url.SEARCHVIP,
      method: 'post',
      data: obj
    }).then(res => {
      console.log('查询 VIP信息成功',res)
      if (res.status ===200) {
        return res.data
      }
    }).catch(err =>{
      console.log(err)
    })
  },//查询 vip
  rechargeAC({commit},obj) {
    console.log('开始充值')
    return http({
      url: '/api'+ url.RECHARGE,
      method: 'post',
      data:obj
    }).then(res => {
      if (res.data.code === '200') {
        return res.data
      }
    }).catch(err => {
      console.log(err)
    })
  },//充值
  verifyIdCardAC({commit},obj) {
        return http({
      url: '/api'+url.VERIFY_IDCARD,
      method: 'post',
      data: obj
    }).then(res => {
      console.log(res)
      if (res.status === 200) {
        return res.data
      }
    }).catch(err => {
      console.log(err)
    })
  },//验证身份证是否正确
  verifyTelAC({commit},obj) {
    console.log('验证电话号码的参数:',obj)
    return http({
      url: '/api'+url.VERIFY_TEL,
      method: 'post',
      data: obj
    }).then(res => {
      if (res.status === 200) {
        return res.data
      }
    }).catch(err => {
      console.log(err)
    })
  },//验证电话号码
  verifyPass({commit},obj) {
    console.log('验证会员的密码',obj)
    return http({
      url: '/api'+url.VERIFY_PASS,
      method: 'post',
      data: obj
    }).then(res => {
      console.log(res)
      if (res.data.code === '200') {
        return res.data.status
      }
      
    }).catch(err => {
      console.log(err)
    })
  },//验证会员的密码是否正确
  
}
const getters ={

}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
